home *** CD-ROM | disk | FTP | other *** search
- /*
- // ##########################################################################
- // #### ####
- // #### TDMouse - A serial mouse driver for the Amiga ####
- // #### =============================================== ####
- // #### ####
- // #### Clock.c ####
- // #### ####
- // #### Version 1.00 -- October 06, 2000 ####
- // #### ####
- // #### Copyright (C) 1995 Thomas Dreibholz ####
- // #### Molbachweg 7 ####
- // #### 51674 Wiehl/Germany ####
- // #### EMail: Dreibholz@bigfoot.com ####
- // #### WWW: http://www.bigfoot.com/~dreibholz ####
- // #### ####
- // ##########################################################################
- */
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-
- #define TITLE "\nTDClock Version 1.00 - Copyright (C) 1995 by Thomas Dreibholz"
- #define PI2 (3.14159/180.0)
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
-
- struct IOStdReq *InputIO;
- struct MsgPort *InputPort;
- LONG InputDev=-1L;
- struct Interrupt Interrupt;
- struct Task *ThisTask;
-
- extern APTR IntRoutine;
- UBYTE MidButton=0;
- BOOL ende=FALSE;
- LONG TSignal=-1L;
- ULONG TSignalMask;
- UWORD mx,my,vx,vy;
- UBYTE std,min,sek;
-
- struct Screen *scr;
- struct RastPort *rp;
- struct ViewPort *vp;
- struct DateStamp ds;
-
- void IntHandler();
- void ShowTime();
- void ShowClock();
- extern FLOAT cos();
- extern FLOAT sin();
-
- struct NewScreen ns=
- {
- 0,0,640,STDSCREENHEIGHT,2,
- 0,1,
- HIRES,
- CUSTOMSCREEN|SCREENQUIET,
- 0L,0L,0L,0L
- };
-
- void CloseAll()
- {
- if(InputDev==0)
- {
- InputIO->io_Data=&Interrupt;
- InputIO->io_Command=IND_REMHANDLER;
- DoIO(InputIO);
- CloseDevice(InputIO);
- }
- if(InputIO) DeleteExtIO(InputIO);
- if(InputPort) DeletePort(InputPort);
- if(TSignal!=-1) FreeSignal(TSignal);
- if(IntuitionBase) CloseLibrary(IntuitionBase);
- if(GfxBase) CloseLibrary(GfxBase);
- exit(0);
- }
-
- void OpenAll()
- {
- if((FindPort(TITLE))!=NULL)
- {
- puts("Das Programm wurde bereits gestartet. Ende mit Alt-F4!");
- CloseAll();
- }
-
- ThisTask=FindTask(NULL);
- IntuitionBase=OpenLibrary("intuition.library",0L);
- GfxBase=OpenLibrary("graphics.library",0L);
- if((IntuitionBase==NULL)||(GfxBase==NULL)) CloseAll();
-
- InputPort=CreatePort(TITLE,0L);
- if(InputPort==NULL)
- { puts("FEHLER: Kann MsgPort nicht erstellen!");
- CloseAll(); }
-
- InputIO=CreateExtIO(InputPort,sizeof(struct IOStdReq));
- if(InputIO==NULL)
- { puts("FEHLER: Kann IOStdReq nicht erstellen!");
- CloseAll(); }
-
- TSignal=AllocSignal(-1L);
- if(TSignal==-1L)
- { puts("FEHLER: Kann Task-Signal nicht belegen!");
- CloseAll(); }
- TSignalMask=(1L<<TSignal);
-
- InputDev=OpenDevice("input.device",0,InputIO,0);
- if(InputDev!=NULL)
- { puts("FEHLER: Kann input.device nicht öffnen!");
- CloseAll(); }
-
- Interrupt.is_Data=NULL;
- Interrupt.is_Code=&IntRoutine;
- Interrupt.is_Node.ln_Succ=NULL;
- Interrupt.is_Node.ln_Pred=NULL;
- Interrupt.is_Node.ln_Type=NT_INTERRUPT;
- Interrupt.is_Node.ln_Name="clock.interrupt";
- Interrupt.is_Node.ln_Pri=51;
- InputIO->io_Data=&Interrupt;
- InputIO->io_Command=IND_ADDHANDLER;
- printf("%d\n",DoIO(InputIO));
- }
-
- #asm
- public _IntRoutine
- public _geta4
- _IntRoutine:
- movem.l a0-a6/d0-d7,-(sp)
- move.l a0,-(sp)
- jsr _geta4
- jsr _IntHandler
- addq.w #4,sp
- movem.l (sp)+,a0-a6/d0-d7
- rts
- #endasm
-
- void IntHandler(Event)
- struct InputEvent *Event;
- {
- if(Event->ie_Class==IECLASS_RAWMOUSE)
- {
- if(Event->ie_Code==(IECODE_MBUTTON|IECODE_UP_PREFIX))
- {
- Disable();
- if(MidButton==0) MidButton=1; else MidButton=0;
- Enable();
- Signal(ThisTask,TSignalMask);
- }
- }
- else if(Event->ie_Class==IECLASS_RAWKEY)
- {
- if(Event->ie_Code==0x53)
- {
- if((Event->ie_Qualifier & IEQUALIFIER_LALT) || (Event->ie_Qualifier & IEQUALIFIER_RALT))
- {
- Disable();
- ende=TRUE;
- Enable();
- Signal(ThisTask,TSignalMask);
- }
- }
- }
- }
-
- void main()
- {
- UWORD ticks;
- UBYTE m=0,mb;
-
- puts(TITLE);
- OpenAll();
-
- while(ende==FALSE)
- {
- if(scr==NULL)
- Wait(TSignalMask);
- else
- {
- Delay(10);
- ticks+=10;
- if((ticks % 50)==0) ShowTime();
- if(ticks>=150) { ShowClock(); ticks=0; }
- }
-
- Disable();
- mb=MidButton;
- Enable();
-
- if((mb==1)&&(m==0))
- {
- m=1;
- scr=OpenScreen(&ns);
- if(scr!=NULL)
- {
- rp=&scr->RastPort;
- vp=&scr->ViewPort;
- SetRGB4(vp,0,0,0,0);
- SetRGB4(vp,1,15,15,5);
- SetRGB4(vp,2,8,8,8);
- SetRGB4(vp,3,15,0,0);
- srand((FLOAT)100);
- mx=0xFFFF;
- vx=95;
- vy=40;
- ticks=0;
- ShowClock();
- }
- }
- else if((mb==0)&&(m==1))
- {
- m=0;
- if(scr)
- {
- CloseScreen(scr);
- scr=NULL;
- }
- }
- }
- if(scr) CloseScreen(scr);
- CloseAll();
- }
-
- void Out(x,y,text)
- UWORD x,y;
- UBYTE *text;
- {
- SetAPen(rp,3);
- Move(rp,x,y);
- Text(rp,text,strlen(text));
- }
-
- void ShowTime()
- {
- UBYTE buffer[20];
-
- DateStamp(&ds);
- std=ds.ds_Minute/60,
- min=ds.ds_Minute % 60,
- sek=ds.ds_Tick / 50;
-
- sprintf(&buffer,"%2d:%02d:%02d",std,min,sek);
- Out(15,15,&buffer);
- }
-
- void ShowClock()
- {
- REGISTER UWORD x,y,i;
- REGISTER UWORD xstd,xmin;
-
- if(mx!=0xFFFF)
- {
- SetAPen(rp,0);
- RectFill(rp,mx-vx-2,my-vy-1,mx+vx+2,my+vy+1);
- }
- ShowTime();
-
- mx=(rand() % (636-2*vx-2))+vx;
- my=(rand() % (196-2*vy-2))+vy;
-
- x=(UWORD)((FLOAT)mx+(FLOAT)vx*cos(0.0));
- y=(UWORD)((FLOAT)my+(FLOAT)vy*sin(0.0));
- SetAPen(rp,1);
- RectFill(rp,mx-2,my-1,mx+2,my+1);
-
- SetAPen(rp,2);
- Move(rp,x,y);
- for(i=0;i<=360;i+=3)
- {
- x=(UWORD)((FLOAT)mx+(FLOAT)vx*cos((FLOAT)i*PI2));
- y=(UWORD)((FLOAT)my+(FLOAT)vy*sin((FLOAT)i*PI2));
- Draw(rp,x,y);
- }
-
- for(i=0;i<=360;i+=(360/12))
- {
- x=(UWORD)((FLOAT)mx+(FLOAT)vx*cos((FLOAT)i*PI2));
- y=(UWORD)((FLOAT)my+(FLOAT)vy*sin((FLOAT)i*PI2));
- SetAPen(rp,1);
- RectFill(rp,x-2,y-1,x+2,y+1);
- SetAPen(rp,2);
- }
-
- xmin=min*6-90;
- SetAPen(rp,3);
- Move(rp,mx,my);
- x=(UWORD)((FLOAT)mx+(FLOAT)vx/1.2*cos((FLOAT)xmin*PI2));
- y=(UWORD)((FLOAT)my+(FLOAT)vy/1.2*sin((FLOAT)xmin*PI2));
- Draw(rp,x,y);
-
- if(std>11) std-=12;
- xstd=(UWORD)((FLOAT)((FLOAT)std/12.0)*360.0+(FLOAT)((FLOAT)xmin/12.0))-90;
- SetAPen(rp,2);
- Move(rp,mx,my);
- x=(UWORD)((FLOAT)mx+(FLOAT)vx/2.0*cos((FLOAT)xstd*PI2));
- y=(UWORD)((FLOAT)my+(FLOAT)vy/2.0*sin((FLOAT)xstd*PI2));
- Draw(rp,x,y);
- }
-
-